package com.example.thegreatwall.utils;


import com.alibaba.fastjson.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author 文晓平
 * @version 1.0
 * @Description 微信工具类
 * @date 2025/6/1 15:59
 */
public class WxUtil {
    private static final String APPID = "wxd096de9d4cf9ceff";
    private static final String SECRET = "dcb75daeaa1b05d56f90c610f4b1dc51";

    public static JSONObject getSessionInfo(String code) throws Exception {
        String url = String.format(
                "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code",
                APPID, SECRET, code
        );
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).build();
        try (Response response = client.newCall(request).execute()) {
            String body = response.body().string();
            return JSONObject.parseObject(body);
        }
    }
}
